//
//  CollectionBaseCell.swift
//  SwiftDemo
//
//  Created by 李国卿 on 2020/1/17.
//  Copyright © 2020 guoqing.li. All rights reserved.
//

import UIKit
import Kingfisher

class CollectionBaseCell: UICollectionViewCell {
    // MARK: 控件属性
    @IBOutlet weak var iconImageView: UIImageView!
    
    @IBOutlet weak var nickNameLabel: UILabel!
    
    @IBOutlet weak var onlineButton: UIButton!
    
    //定义模型类型
    var anchor : AnchorModel?{
        didSet{
            // 1.校验是否有值
            guard let anchor = anchor else {return}
            // 2.取出在线人数显示文字
            var onlineStr: String = ""
            if anchor.online >= 10000  {
                onlineStr = "\(anchor.online/10000)万在线"
            }else{
                onlineStr = "\(anchor.online)在线"
            }
            onlineButton.setTitle(onlineStr, for: .normal)
            // 3.设置昵称
            nickNameLabel.text = anchor.nickname
            // 4.设置图片
            guard let iconUrl = NSURL(string: anchor.vertical_src) else {return}

            let url = ImageResource(downloadURL: iconUrl as URL)
            iconImageView.kf.setImage(with: url, placeholder:  UIImage(named: "Img_default"))
            iconImageView.layer.cornerRadius = 4.0;
            iconImageView.layer.masksToBounds = true;
        }
    }
    
}
